﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataAccessLayer;

namespace BusinessLogicLayer
{
    public class TongCongThangBLL
    {
        QuanLyChamCongDataContext DB = new QuanLyChamCongDataContext();

        public List<TONGCONGTHANG> LayTatCa()
        {
            return DB.TONGCONGTHANGs.ToList();
        }

        public List<TONGCONGTHANG> LayDSTongCong(int thang, int nam)
        {
            List<TONGCONGTHANG> ls = (from a in DB.TONGCONGTHANGs
                                      where a.Thang == thang && a.Nam == nam
                                      select a).ToList();
            return ls;
        }

        public bool KiemTraTongCong(int thang, int nam)
        {
            if (DB.TONGCONGTHANGs.Any(a => a.Thang == thang && a.Nam == nam))
                return true;
            else
                return false;
        }

        public TONGCONGTHANG LayTongCong(int manv, int thang, int nam)
        {
            return DB.TONGCONGTHANGs.SingleOrDefault(a => a.MaNV == manv && a.Thang == thang && a.Nam == nam);
        }

        public void Them(TONGCONGTHANG a)
        {
            DB.TONGCONGTHANGs.InsertOnSubmit(a);
            DB.SubmitChanges();
        }

        public void Sua(TONGCONGTHANG n)
        {
            TONGCONGTHANG o = DB.TONGCONGTHANGs.Single(a => a.Thang == n.Thang && a.Nam == n.Nam && a.MaNV == n.MaNV);
            o.GioTangCa = n.GioTangCa;
            o.TongCong = n.TongCong;
            o.CongLamViec = n.CongLamViec;
            o.CongTangCa = n.CongTangCa;
            DB.SubmitChanges();
        }
    }
}
